/*!
 * WeiJinSuo Web3.0 with HTML5 and CSS3 spec
 * http://www.weijinsuo.com/
 *
 * Copyright 2014, 微金所 LuDeLiang[ip007@126.com] SunJunChao JinChangJiang GaoQing
 * License   Released under the MFExchange.
 * Date      Wed Oct 28 2015 18:43:16 GMT+0800 (CST)
 *
 * Requires  jQuery v1.11.1, Bootstrap v3
 */
!function (a, b) {
    "object" == typeof module && "object" == typeof module.exports ? module.exports = a.document ? b(a, !0) : function (a) {
        return b(a)
    } : b(a)
}("undefined" != typeof window ? window : this, function (a) {
    var b = function (a) {
        this.opt = $.extend({
            url: "/callApi.do?callUrl=",
            type: "POST",
            dataType: "json",
            loading: !0,
            login: !1
        }, "object" == typeof a ? a : {})
    };
    return b.prototype = {
        auth: function () {
            var a = this.opt.version ? this.opt.version : "20", b = this.opt.source ? this.opt.source : "7";
            return "{'source':'" + b + "','vendor':'100000','osver':'1','appver':'1','version':" + a + ",'base64':'1'}"
        }, option: function (a, b) {
            return "undefined" == typeof b ? this.opt[a] : (this.opt[a] = b, !0)
        }, formatData: function (a) {
            var b = function (a) {
                var c = [];
                for (var d in a) {
                    var e = a[d], f = "'" + d + "':" + ("object" == typeof e ? b(e) : "'" + e + "'");
                    c.push(f)
                }
                return "{" + c.join(",") + "}"
            }, c = this.auth(), d = "string" == typeof a ? a : b(a);
            if (this.opt.login) {
                var e = $.cookie("u");
                "string" == typeof globalUserSession && globalUserSession != e && require(["jquery", "jquery_fn_toastr"], function (a, b) {
                    b.clear(), b.warning("当前用户的登录状态异常，请重新登录！")
                }), d = "{'userSession':'" + e + "'," + d.substr(1)
            }
            return {info: d, auth: c}
        }, get: function (a, b, c) {
            var d = this, e = "function" == typeof c, f = e ? !0 : !1;
            if (callBack = e ? c : function (a) {
                    return a
                }, d.opt.loading)var g = $ ? $.loading() : null;
            a = "/webRequest/" + a;
            var h = $.ajax({
                url: a + "?radom=" + (new Date).getTime(),
                type: d.opt.type,
                dataType: d.opt.dataType,
                async: f,
                data: d.formatData(b),
                success: callBack,
                error: function () {

                },
                complete: function () {
                    g && $.loading(g)
                }
            });
            return h.responseJSON
        }, upload: function (a, b, c, d) {
            var e = this;
            require(["modules/jquery_fn_ajaxfileupload"], function () {
                if (e.opt.loading)var f = $.loading();
                a = "/webRequest/" + a, $.ajaxFileUpload({
                    url: a + "?method=uploader&radom=" + (new Date).getTime(),
                    secureuri: !1,
                    fileElementId: b,
                    data: e.formatData(d ? d : "{}"),
                    dataType: e.opt.dataType,
                    success: c,
                    complete: function () {
                        f && $.loading(f)
                    },
                    error: function (a) {
                        f && $.loading(f), alert(a.responseText.match(/^[\u4e00-\u9fa5]/g))
                    }
                })
            })
        }, check: function (b) {
            var c = this;
            if (b && "0" == b.respcode)return !0;
            if (b && b.respcode < 0 && b.respcode > 9e3) {
                if (1 != localStorage.getItem("orgType") && $.cookie("g", a.location.href), "undefined" == typeof marTheApimustLogin || $.cookie("u")) {
                    if (marTheApimustLogin = !0, $.cookie("u", ""), 1 == localStorage.getItem("orgType"))return a.location.href = "/user/login.html", !1;
                    $.alert({
                        title: "温馨提示", content: b.message, type: "", callBack: function (b) {
                            $(".login-timeout:not(:last)").modal("hide"), b.addClass("login-timeout bs-example-modal-sm"), b.find(".modal-body").append('<div class="form-group"><div class="input-group"><div class="input-group-addon"><span class="glyphicon glyphicon-user"></span></div><input class="form-control required" name="username" id="relogin-username" type="text" placeholder="请输入手机号/邮箱" aria-required="true"></div></div><div class="form-group"><div class="input-group"><div class="input-group-addon"><span class="glyphicon glyphicon-pwd"></span></div><input class="form-control required" name="loginPwd" type="password" minlength="6" maxlength="16" placeholder="请输入密码" aria-required="true"></div></div>'), b.find(".modal-footer").append('<a class="btn btn-primary" id="user_login_btn">重新登录</a>'), b.find(".close").mousedown(function () {
                                $.goUrl("/user/login.html")
                            }), $("#user_login_btn").click(function () {
                                globalUserSession = null, c.option("login", !1), c.option("version", "21"), c.get("loginUser.do", {
                                    username: $("#relogin-username").val(),
                                    loginPwd: $.base64($("[name=loginPwd]").val())
                                }, function (b) {
                                    if ("0" == b.respcode) {
                                        var c = b.result, d = c.userSession, e = [c.userId, c.username, c.phone, c.email, c.userLevel, c.authLevel];
                                        e.push($.handleTime()), e.push(c.headPic);
                                        var f = [];
                                        c.permissionList && c.permissionList.length && $.each(c.permissionList, function (a, b) {
                                            f.push(b.code)
                                        }), e.push(f.join(",")), e.push(c.loanStatus), $.cookie("u", d), $.cookie("ul", e.join("&"), {expires: 15}), a.location.reload()
                                    } else require(["jquery", "jquery_fn_toastr"], function (a, c) {
                                        c.error(b.message)
                                    })
                                })
                            }), b.find("input[name=loginPwd]").keyup(function (a) {
                                13 == a.keyCode && b.find("#user_login_btn").click()
                            }), b.on("hidden.bs.modal", function () {
                                $.goUrl("/user/login.html")
                            })
                        }
                    })
                }
            } else require(["jquery", "jquery_fn_toastr"], function (a, c) {
                c.clear() ;
                if(b){
                    c.error(b.message)
                }
            });
            return !1
        }
    }, "function" == typeof define && define.amd && define("api", [], function () {
        return b
    }), a.wjsApi = b, b
});